//
//  Graph.cpp
//  Ej3TP2
//
//  Created by Jonathan Melnik on 4/18/14.
//  Copyright (c) 2014 ___JonathanMelnik___. All rights reserved.
//

#include "Graph.h"
#include "Arrow.h"
#include <iostream>

using namespace std;
Graph::Graph(int rows, int cols) {
    this->rows = rows;
    this->cols = cols;
    nodes.resize(cols*rows);
    for (int row = 0; row < rows; row++) {
        for(int col = 0; col < cols; col++) {
            nodes[col+row*cols] = new Node(row, col, 0);
        }
    }
}

Node* Graph::getNode(int row, int col) {
    return nodes[col+row*cols];
}

void Graph::connect(Node* fromNode, Node* toNode, int powerUsed, int kUsed) {
    fromNode->connectToNextNode(toNode, powerUsed, kUsed);
}

Graph::~Graph() {
    for (int row = 0; row < rows; row++) {
        for(int col = 0; col < cols; col++) {
            delete nodes[col+row*cols];
        }
    }
}
